package cn.lf.exception;

import cn.lf.utils.ResponseModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 异常处理器
 * @author guoyy
 */
@RestControllerAdvice
@Slf4j
public class ExceptionHandlerAdvice {

    @ExceptionHandler(Exception.class)
    public ResponseModel handleException(Exception e){
        ResponseModel responseModel = ResponseModel.getSysError();
        if (e instanceof SelfException){
            SelfException selfException = (SelfException) e;
            responseModel.setCode(selfException.getCode());
            responseModel.setMsg(selfException.getMsg());
        }else{
            responseModel.setCode(500);
            responseModel.setMsg(e.getMessage());
        }
        return responseModel;

    }
}
